﻿using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RDWSMTool.ViewModels.Dialogs
{
    public class AddDileveryOrderDialogViewModel : BindableBase, IDialogAware
    {
        public string Title => "添加研发出库单";
        private string code;
        public string Code
        {
            get { return code; }
            set { SetProperty(ref code, value); }
        }
        private string remark;
        public string Remark
        {
            get { return remark; }
            set { SetProperty(ref remark, value); }
        }
        private DateTime createDate;
        public DateTime CreateDate
        {
            get { return createDate; }
            set { SetProperty(ref createDate, value); }
        }
        private DelegateCommand<object> buttonCommand;
        public DelegateCommand<object> ButtonCommand =>
            buttonCommand ?? (buttonCommand = new DelegateCommand<object>(ExecuteButtonCommand));
        void ExecuteButtonCommand(object obj)
        {
            switch (obj.ToString())
            {
                case "0":
                    {
                        DialogParameters param = new DialogParameters();
                        param.Add("Remark", Remark);
                        param.Add("Created", CreateDate);
                        RaiseRequestClose(new DialogResult(ButtonResult.Yes, param));
                    }
                    break;
                case "1":
                    {
                        RaiseRequestClose(new DialogResult(ButtonResult.No));
                    }
                    break;
                default:
                    break;
            }
        }
        public event Action<IDialogResult> RequestClose;
        public virtual void RaiseRequestClose(IDialogResult dialogResult)
        {
            RequestClose?.Invoke(dialogResult);
        }

        public bool CanCloseDialog()
        {
            return true;
        }

        public void OnDialogClosed()
        {
           
        }

        public void OnDialogOpened(IDialogParameters parameters)
        {
            Code = parameters.GetValue<string>("Code");
            Remark = "";
            CreateDate = DateTime.Now;
        }
    }
}
